package cn.tedu.boqi.shop.order.controller;

import cn.tedu.boqi.shop.order.pojo.dto.CartAddDto;
import cn.tedu.boqi.shop.order.pojo.dto.CartUpdateDTO;
import cn.tedu.boqi.shop.order.service.CartService;
import cn.tedu.boqi.shop.order.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "购物车控制器")
@RequestMapping("/cart")
public class CartController {
    @Autowired
    CartService cartService;


    @ApiOperation("添加到购物车")
    @ApiOperationSupport(order = 100)
    @PostMapping ("/add")
    public JsonResult add(CartAddDto cartAddDto){
        cartService.add(cartAddDto);
        return JsonResult.ok();
    }

    @ApiOperation("修改购物车商品状态")
    @ApiOperationSupport(order = 300)
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Integer> update(@PathVariable("id") Long id, CartUpdateDTO cartUpdateDTO){
        Integer status = cartService.updateStatus(id, cartUpdateDTO);
        return JsonResult.ok(status);
    }
}
